<!--This page is to override the Crud.show of the Tasks, I specified some attributes to appear
	while editing.
	Author: Monayri
-->

#{extends 'overlay.html' /}
#{set 'moreStyles'}
<style type="text/css">
	.ac_results {
		background: #eee;
		border: 2px solid #bbb;
		border-radius:10px;
		border-top-right-radius: 0;
		border-top-left-radius: 0;
	}
	.ac_results ul {
		list-style: none;
	}
	.ac_results ul li {
		font-size:small;
	}
	
</style>
#{/set}

<script type="text/javascript" src="@{'/public/javascripts/jquery.autocomplete.js/'}"></script>

<div id="crudShow" class="${type.name}">
	
	<h2 id="crudShowTitle">&{'crud.show.title', type.modelName}</h2>
	<font color="Red">${message}</font>

	<div class="objectForm">
	#{form action:@save(object.id), enctype:'multipart/form-data'}
	#{crud.form fields:['parent','description','reporter','successScenario','failureScenario','component','taskStatus','taskType','assignee','reviewer','taskSprint','estimationPoints','priority','subTasks','dependentTasks']}		
			#{crud.custom 'parent'}
			#{if object.parent!=null}
			<label for="task_parent">Parent</label> 
			<span id="task_Story2"><font color="green">${object.parent.getSummary()}</font></span> 
			#{/if}
			#{/crud.custom }
			
			#{crud.custom 'description' }
			<label for="object_description">Description	</label>
			<textarea id="object_description"  name="object.description" style="width:100%;height:70px"onclick="f();">${object.getSummary()}</textarea>
    		<span class="crudHelp" style="color:red">*</span>
			<div style="display:none" class="d">Ex: As a/an product role, description</div>
			<span class="error"></span>
			#{/crud.custom}
			
			#{crud.custom 'successScenario' }
			<label for="object_successScenario">Success Scenario</label>
			<textarea id="object_successScenario"style="width:100%;height:70px"  name="object.successScenario">${object.successScenario}</textarea>
    		<span class="error"></span>
			#{/crud.custom}
			
			#{crud.custom 'failureScenario' }
			<label for="object_failureScenario">Failure Scenario</label>
			<textarea id="object_failureScenario" style="width:100%;height:70px" name="object.failureScenario">${object.failureScenario}</textarea>
    		<span class="error"></span>
			#{/crud.custom}
					
			#{crud.custom 'taskStatus'}
			<label for="task_taskStatus">Status</label>
			<select style="min-width:130px" id="object_taskStatus" name="object.taskStatus@id">
			#{if object.taskStatus==null}
				<option value="">(None)</option>
			#{/if}
			#{list items:statuses ,as :'Status'}
				#{ifnot Status.deleted}<option value="${Status.id}"#{if object.taskStatus == Status} selected#{/if}>${Status.name}</option>#{/ifnot}
			#{/list}		
			</select>
			#{/crud.custom }
				
			#{crud.custom 'taskType'}
			#{if object.project.hasTypes()>0}
				<label for="task_type">Type</label> 
				<select style="min-width:130px" id="object_taskType" name="object.taskType@id" onchange="getType();">
				#{if object.taskType==null}<option value="">(None)</option>#{/if}
				#{list items:object.project.taskTypes ,as :'Type'}
					#{if !Type.deleted}<option value="${Type.id}"#{if object.taskType == Type} selected#{/if}>${Type.name}</option>#{/if}									
				#{/list}		
				</select>
			#{/if}#{else}#{/else}
			#{/crud.custom }
			
			#{crud.custom 'component'}
			#{if object.project.hasComponents()==1}#{/if}
			#{elseif (insprint || object.parent!=null) && object.component!=null && object.component.number!=0}
				<label for="task_type">Component</label>
				<span ><font color="green">${object.component.name}</font></span>
			#{/elseif}
			#{else}
				<label for="task_type">Component</label>
				<select style="min-width:130px" id="object_component" name="object.component@id" onchange="getUsers();getType();">
				#{list items:object.project.components ,as :'component'}
					#{if component.number==0}<option value="${component.id}"#{if object.component == component} selected#{/if}>None</option>#{/if}
					#{elseif !component.deleted}<option value="${component.id}"#{if object.component == component} selected#{/if}>${component.name}</option>#{/elseif}
			#{/list}		
			</select>
			#{/else}
			#{/crud.custom }
			
			#{crud.custom 'estimationPoints'}
			<label for="object_estimationPoints">Estimation Points</label> 
			<input id="object_estimationPoints" type="text" name="object.estimationPoints" 
			size="5"  value = "${object.estimationPoints}"/> 
			<span class="crudHelp" ><font color="Red">*</font>Numeric.</span> 
 			#{/crud.custom }
			
			#{crud.custom 'priority'}
			#{if object.project.hasPriorities()}
			<label for="object_priority">Priority</label> 
			<select style="min-width:130px" id="object_priority" name="object.priority">
			<option value="">None</option>
			#{list items:object.project.priorities ,as :'priority'}
				#{ifnot priority.deleted}<option value="${priority.priority}"#{if object.priority == priority} selected#{/if}>${priority.priority}</option>#{/ifnot}
			#{/list}
			</select>
			#{/if}#{else}#{/else}
			#{/crud.custom }
			
			
			#{crud.custom 'reporter'}
			<label for="task_reporter">Reporter</label> 
			<span id="task_reporter2" ><font color="green">${object.reporter.name}</font></span> 
			#{/crud.custom }
			
			#{crud.custom 'assignee'}
			#{if object.component!=null && object.component.number==0 && object.project.hasUsers()>0}
				<label for="object_assignee">Assignee</label>
				<span style="display:none" id="assig_msg"><font color="red">There are no users in the selected component</font></span>
				<select style="min-width:130px" class="assign" id="object_assignee" name="object.assignee@id"  onchange="getType();">
				<option value="">(None)</option>
				#{list items:object.project.users ,as :'User'}
					#{ifnot User.deleted}<option value="${User.id}"#{if object.assignee == User} selected#{/if}>${User.name}</option>#{/ifnot}
				#{/list}		
				</select>
			#{/if}
			#{elseif object.component!=null && object.component.number!=0 && (object.parent==null || (object.parent!=null && object.parent.component!=null && object.component.hasUsers()>0))}
				<label for="object_assignee">Assignee</label>
				<span style="display:none" id="assig_msg"><font color="red">There are no users in the selected component</font></span>
				<select style="min-width:130px" class="assign" id="object_assignee" name="object.assignee@id"  onchange="getType();">
				<option value="">(None)</option>
				#{list items:object.component.componentUsers ,as :'User'}
					#{ifnot User.deleted}<option value="${User.id}"#{if object.assignee == User} selected#{/if}>${User.name}</option>#{/ifnot}
				#{/list}		
				</select>
			#{/elseif}#{else}#{/else}
			#{/crud.custom}
	
			#{crud.custom 'reviewer'}
			#{if object.component!=null && object.component.number==0 && object.project.hasUsers()>0}
				<label for="object_reviewer">Reviewer</label>
				<span style="display:none" id="rev_msg"><font color="red">There are no reviewers available for the selected type</font></span>
				<select style="min-width:130px" class="rev" id="object_reviewer" name="object.reviewer@id">
				<option value="">(None)</option>
				#{list items:users ,as :'User'}
					#{ifnot User.deleted}<option value="${User.id}"#{if object.reviewer == User} selected#{/if}>${User.name}</option>#{/ifnot}
				#{/list}		
				</select>
			#{/if}
			#{elseif object.component!=null && object.component.number!=0 && (object.parent==null || (object.parent!=null && object.parent.component!=null && object.component.hasUsers()>0))}
				<label for="object_reviewer">Reviewer</label>
				<span style="display:none" id="rev_msg"><font color="red">There are no reviewers available for the selected type</font></span>
				<select style="min-width:130px" class="rev" id="object_reviewer" name="object.reviewer@id">
				<option value="">(None)</option>
				#{list items:users ,as :'User'}
					#{ifnot User.deleted}<option value="${User.id}"#{if object.reviewer == User} selected#{/if}>${User.name}</option>#{/ifnot}
				#{/list}		
				</select>
			#{/elseif}#{else}#{/else}
			#{/crud.custom}
	
			#{crud.custom 'dependentTasks'}
			#{if object.project.hasTasks()>1}
				<label for="object_dependentTasks"> Dependent Tasks</label> 
				<input type="hidden" name="object.dependentTasks@id" value="" /> 
				<select id="object_dependentTasks" name="object.dependentTasks@id" style="margin:10px 0;width:100%;height:70px" multiple="yes"> 
				#{list items:object.project.projectTasks ,as :'Task'}
					#{if !Task.deleted && object!=Task}<option value="${Task.id}" #{if object.dependentTasks.contains(Task)}selected#{/if}>${Task.getSummary()}</option>#{/if}
				#{/list} 
				#{if object.dependentTasks.size()>0}<option value="">None</option>#{/if}
				</select>
			#{/if}#{else}#{/else}
			#{/crud.custom }
			
			#{crud.custom 'taskSprint'}
			#{if (object.taskSprint!=null && object.taskSprint.ended()) || insprint}<label for="object_taskSprint">Sprint</label>
				<span id="task_taskSprint" ><font color="green">sprint ${object.taskSprint.sprintNumber}</font></span>#{/if}
			#{elseif sprints.size()>0}
				<label for="object_taskSprint">Sprint</label>
					<select style="min-width:130px" id="object_taskSprint" name="object.taskSprint@id">
					<option value="">(None)</option>
					#{list items:sprints ,as :'sprint'}
						<option value="${sprint.id}"#{if object.taskSprint == sprint} selected#{/if}>sprint ${sprint.sprintNumber}</option>
					#{/list}
					</select>
				
			#{/elseif}#{else}<label for="object_taskSprint">Sprint</label>
			<span><font color="red">There are currently no upcoming sprints</font></span>
			#{/else}
			#{/crud.custom }
			
	
			#{if object.subTasks.size()==0}
			#{crud.custom 'subTasks'}
			#{/crud.custom}
			#{/if}
			
		#{/crud.form }
		
		<p class="crudButtons">
			<input type="submit" name="_save" value="&{'crud.save', type.modelName}" />
		</p>
	#{/form}
	</div>
	#{if deletable}
	
	#{/if}
	
	#{if !deletable}
		<label><font color="green">&nbsp;&nbsp;The task can't be deleted As some other tasks depends on it !</font></label>
	#{/if}
</div>

<script type="text/javascript">

	if(${users.size()}==0)
	{
		$('#rev_msg').css('display', 'inline-block');
		$('.rev').css('display','none');
	}
	var data='${productRoles}'.split("-");
	$("#object_description").autocomplete(data);
	
	function f()
	{
		$('.d').css('display','inline-block');
	}
	
	function product_role(id)
	{
		$.post('/Storys/addProductRole' ,			
			{projectID:id,						
			description:$("#example").val()});
	} 

	function change_reviewers(projId){
    var value = $('#object_component').val();
	var value2 = $('#object_assignee').val();
	var compId = $('#object_component').val();
    $.post('@{reviewers}', {id:value, id2 : value2, compId: compId, projId:projId}, function(data){
		str = '<option value="">(None)</option>';
		$.each(data, function(id, item){
			str += '<option value='+item.id+'>'+item.name+'</option>';
		});
		$('#object_reviewer').html( str );
	});
    }

	function deleteComment(cId,tIdd){
	if(confirm("Are you sure you want to delete this comment? This action can not be undone.")){
		$.post('/comments/deleteComment', {id:cId}, function(msg){
			$.bar({message:msg});
		});
		window.location.reload();
	}
	}
function getUsers()
{
	var compId = $('#object_component').val();
	var typeId = $('#object_taskType').val();
	$.post('@{component_users}', {id : compId}, function(data){
		str = '<option value="">(None)</option>';
		$.each(data, function(id, item){
			str += '<option value='+item.id+'>'+item.name+'</option>';
		});
		$('#object_assignee').html( str );
		if (data.length == 0) {
			$('.assign').css('display', 'none');
			$('#assig_msg').css('display', 'inline-block');
		}
		else 
		{
			$('#assig_msg').css('display', 'none');
			$('.assign').css('display', 'inline-block');
		}
	}); 
	$.post('@{type_reviewer}', {type_id : typeId, component_id:compId}, function(data){
		str = '<option value="">(None)</option>';
		$.each(data, function(id, item){
			str += '<option value='+item.id+'>'+item.name+'</option>';
		});
		$('#object_reviewer').html( str );
	}); 
}
function getType()
{
	var compId = $('#object_component').val();
	var typeId = $('#object_taskType').val();
	var assigneeId = $('#object_assignee').val();
	$.post('@{type_reviewer}', {type_id : typeId, component_id:compId, assigneeId:assigneeId}, function(data){
		str = '<option value="">(None)</option>';
		$.each(data, function(id, item){
			str += '<option value='+item.id+'>'+item.name+'</option>';
		});
		$('#object_reviewer').html( str );
		if (data.length == 0) {
			$('.rev').css('display', 'none');
			$('#rev_msg').css('display', 'inline-block');
		}
		else 
		{
			$('.rev').css('display', 'inline-block');
			$('#rev_msg').css('display', 'none');
		}
	}); 
}
	</script>

